package com.sysmanage.etl.controls;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.sysmanage.etl.model.ETL_Property;
import com.sysmanage.etl.service.IPropertyService;
import com.sysmanage.etl.vo.PropertyFullVO;

@Scope("prototype")
@Controller(value = "propertyTg")
public class PropertyTg extends ActionSupport implements Preparable, ModelDriven<PropertyFullVO> {
	private static final long serialVersionUID = -45748656092879535L;
	@Resource
	private IPropertyService propertyService;
	private PropertyFullVO propertyVO;
	private Map<String, Object> result = new HashMap<String, Object>();

	public String update() {
		return "updateJSON";
	}

	public void prepareUpdate() {

		ETL_Property property = this.propertyService.findById(this.propertyVO.getProperty_id());
		property.setProperty_alias(this.propertyVO.getProperty_alias());
		property.setProperty_desc(this.propertyVO.getProperty_desc());
		property.setProperty_defaultValue(this.propertyVO.getProperty_defaultValue());

		boolean isUpdateSuccess = this.propertyService.alter(property);
		if (isUpdateSuccess) {
			result.put("message", "操作成功!");
			result.put("success", true);
		} else {
			result.put("message", "操作失败!");
			result.put("success", false);
		}
	}

	public Map<String, Object> getResult() {
		return result;
	}

	@Override
	public PropertyFullVO getModel() {
		if (propertyVO == null) {
			propertyVO = new PropertyFullVO();
		}
		return propertyVO;
	}

	public PropertyFullVO getPropertyVO() {
		return propertyVO;
	}

	public void setPropertyVO(PropertyFullVO propertyVO) {
		this.propertyVO = propertyVO;
	}

	@Override
	public void prepare() throws Exception {
	}

	private Integer total = 0;
	
	public Integer getTotal() {
		return this.total;
	}
	
	
	
}
